package com.airlines.crewassignment.controller.report;

import java.util.Date;
import java.util.List;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.airlines.common.Page;
import com.airlines.crewassignment.domain.Crew;
import com.airlines.crewassignment.domain.CrewTask;
import com.airlines.crewassignment.domain.DateTimeRange;
import com.airlines.crewassignment.entity.crew.CrewSchedule;
import com.airlines.crewassignment.service.crew.CrewService;
import com.airlines.crewassignment.service.crew.CrewTaskService;

/**
 * @author xianghaini
 * @date created in   2018/7/16 15:07
 * @description  人员在位情况统计表
 */
@Controller
@RequestMapping("/crewTaskReport")
public class CrewTaskReportController {
    private static final String PREFIX = "/report";
    @Autowired
    private CrewService  crewService;
    @Autowired
    private CrewTaskService crewTaskService;



    /**
     * 进入页面
     * @return
     */
    @RequestMapping(value = "", method={ RequestMethod.GET})
    // @RequiresPermissions("report:crewTaskReport:list")
    String toCrewTaskReportPage(Model model, String moduleFlag){
        model.addAttribute("moduleFlag",moduleFlag);
        return PREFIX + "/crewTaskReportList";
    }

    /**
     * 多条件模糊 查询人员信息
     * @param moduleFlag  人员类型
     * @param workcode
     * @return
     */
    @RequestMapping(value = "/listCrew")
    @ResponseBody
    // @RequiresPermissions("crewlocation:crewAbsent:list")
    public Object list( String moduleFlag,String workcode) {
        // 基本信息查询
        List<Crew> crewList = crewService.listCrewInfoForVo(moduleFlag,workcode);
        // 任务初始化
        return (crewList);
    }



    /**
     * 多条件模糊 查询人员的任务列表
     * @return
     */
    @RequestMapping(value = "/listTask")
    @ResponseBody
    // @RequiresPermissions("crewlocation:crewAbsent:list")
    public Object list(Date startDate,Date endDate, String workcode,String moduleFlag) {
        DateTime endDateTime = new DateTime(endDate).millisOfDay().withMaximumValue();
        DateTimeRange dateTimeRange = new DateTimeRange(startDate, endDateTime.toDate());
        List<CrewSchedule> list = crewTaskService.listCrewSchedule(dateTimeRange, moduleFlag, workcode);
        return (list);
    }

    
    /**
     * 查询人员的日历甘特图
     * @return
     */
    @RequestMapping(value = "/listCrewTaskPage")
    @ResponseBody
    public Object listCrewTaskAll(Date startDate,Date endDate, String[] workcodeArray,String moduleFlag) {
        DateTime endDateTime = new DateTime(endDate).millisOfDay().withMaximumValue();
        DateTimeRange dateTimeRange = new DateTimeRange(startDate, endDateTime.toDate());
        List<CrewTask> list = crewTaskService.listCrewTaskPage(dateTimeRange, moduleFlag, workcodeArray);
        return (list);
    }
    
    /**
     * 分页查询资源Y轴
     * @param moduleFlag  人员类型
     * @param workcode
     * @return
     */
    @RequestMapping(value = "/listCrewPage")
    @ResponseBody
    public Object list( String moduleFlag,String workcode,String offset, String limit) {
	   Page page = new Page();
       page.setPageNumber((Integer.valueOf(offset) / (Integer.valueOf(limit))));
       page.setPageSize(Integer.valueOf(limit));
       
        // 基本信息查询
        page = crewService.listCrewInfoForVoPage(moduleFlag,workcode,page);
        // 任务初始化
        return (page);
    }

}
